package cn.com.generaldata.os.util;

import java.io.File;
import java.io.StringReader;

import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

public class XMLCheck {
	public boolean Xml2Xsd(String xml, String FilePath) {
		try {
			String schemaLanguage = XMLConstants.W3C_XML_SCHEMA_NS_URI;
			SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
			Schema schema = schemaFactory.newSchema(new File("FilePath"));
			StringReader reader = new StringReader(xml);
			Validator validator = schema.newValidator();
			Source source = new StreamSource(reader);
			validator.validate(source);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

}